/**
 * 评价管理页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：评价管理
     创建日期：2015-10-12
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	queryEvaluates();
	 $(".date").datepicker({
	        todayBtn: "linked",
	        keyboardNavigation: false,
	        forceParse: false,
	        calendarWeeks: true,
	        autoclose: true
	    });
});

/**
 * 查询快递员站点
 * @returns
 */
var queryEvaluates = function(){

    var nickName=$("#nickName").val();		//用户昵称
    var evaluateTime=$("#createTime").val();	//评论提交时间
    var courier=$("#courierName").val();		//快递员名称
    var courierPhone=$("#courierPhone").val();	//快递员手机号
    var courierCompany=$("#courierCompany").val();	//所属快递公司
    var evaluate=$("#evaluateList2").val();		//评论
    var spitslot=$("#spitslot").val();		//吐槽内容
    var orderId=$("#orderId").val(); //订单ID
	
	 var datas =  {"p":"evaluateManage","m":"q","senderNickName":nickName,"createTime":evaluateTime,"courierName":courier,"courierPhone":courierPhone,"code":courierCompany,"score":evaluate,"content":spitslot,"orderId":orderId};
	 var columnDefine = {"id":"ID","senderNickName":"用户昵称","createTime":"评论提交时间","courierName":"快递员","courierPhone":"快递员手机号","company":"快递公司","score":"评价","content":"吐槽内容","order_id":"订单ID"};
	 var formatters={
	            "createTime": function (column, row)
	            {
    				if(row.createTime)
    				{
    					return timeFormatTrans(row.createTime*1000);
    				}
    				else
    				{
    					return "";
    				}
	            },
	            "score": function (column, rowData)
	            {
    				if(rowData.score==""||rowData.score==null){
    					return "";
    				}
    				var cpj="";//评价分值1没来，2不满意，3满意
    				if(rowData.score==1){
    					cpj="没来";
    				}else if(rowData.score==2){
    					cpj="不满意";
    				}else if(rowData.score==3){
    					cpj="满意";
    				}else{
    					
    				}
    				return cpj;
	            },
	            "content": function (column, rowData)
	            {
    				if(rowData.content==null || rowData.content==""){
    					return "";
    				}
    				var contexts="";
    				var re=new RegExp('<','g');
    				var re1=new RegExp('>','g');
    				if(rowData.content.length<=30){
    					contexts=rowData.content.replace(re,'&lt;');
    					contexts=contexts.replace(re1,'&gt;');
    					return contexts;
    				}else{
    					contexts=rowData.content.replace(re,"&lt;");
    					contexts=contexts.replace(re1,"&gt;");
    					return '<span title="'+contexts+'">'+contexts+'</span>';
    				}
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='</p>';
	hui.pager('service',datas ,"evaluateList", columnDefine , formatters , buttons ); //分页查询
	 
};

var getTheSureTime=function(emp){
	return emp>9?emp:"0"+emp;
}
//时间格式转换
var timeFormatTrans=function(time){
	var newTime= new Date(time);
	var rowText=newTime.getFullYear()+'-'+getTheSureTime((newTime.getMonth()+1))+'-'
	+getTheSureTime(newTime.getDate())+' '+getTheSureTime(newTime.getHours())+':'
	+getTheSureTime(newTime.getMinutes())+':'+getTheSureTime(newTime.getSeconds());
	return rowText;
};

/**
 * 导出数据
 * @returns
 */
var exportDatas=function(){
	
	
	 var nickName=$("#nickName").val();		//用户昵称
	 var evaluateTime=$("#createTime").val();	//评论提交时间
	 var courier=$("#courierName").val();		//快递员名称
	 var courierPhone=$("#courierPhone").val();	//快递员手机号
	 var courierCompany=$("#courierCompany").val();	//所属快递公司
	 var evaluate=$("#evaluateList2").val();		//评论
	 var spitslot=$("#spitslot").val();		//吐槽内容
	 var orderId=$("#orderId").val(); //订单ID
		
	var datas =  {"p":"evaluateManage","m":"q","exportData":1,"senderNickName":nickName,"createTime":evaluateTime,"courierName":courier,"courierPhone":courierPhone,"code":courierCompany,"score":evaluate,"content":spitslot,"orderId":orderId};
	
	var rjson=common.ajaxRequest('service', datas , "POST");
	if(rjson && rjson.result == 0){
		if(rjson.exportDataSql){
			dataUrl=rjson.exportDataSql;
		}else{
			common.showMsg('error', '', '导出数据未成功，请刷新重试');
		}
	}else{
		window.parent.pui.cmNotify("导出数据操作失败！");
		common.showMsg('error', '', '导出数据操作失败');
	}
	if(!dataUrl){
		return;		
	}
	var data = {"p":"exportData","sql":dataUrl,"m":"export"};
	var json = common.ajaxRequest('service', data , 'POST');
	common.showMsg('info', '', json.message );
	window.open(json.excelFile);
};


